package com.bstek.zuul;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;


@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
@EnableOAuth2Sso
public class Derek00Zuul9000Application extends WebSecurityConfigurerAdapter{


	public static void main(String[] args) {
		SpringApplication.run(Derek00Zuul9000Application.class, args);
	}

	//重写WebSecurityConfigurerAdapter适配器的configure(HttpSecurity http)方法，声明需要鉴权的url信息。
	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http.csrf().disable()
				.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
				.and()
				.requestMatchers().anyRequest()
				.and()
				.authorizeRequests()
				.antMatchers("/user/**").authenticated()
				.and()
				.formLogin().successForwardUrl("/index")
				.and()
				.logout().logoutUrl("/logout").permitAll()
				.logoutSuccessUrl("/");
	}
}
